package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.MaterialListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.StringUtil;

import java.util.List;

public class OptionAdapter extends BaseRecycleAdapter<MaterialListEntity> {
    private String appIconUrl = "https://shigongbang.oss-cn-hangzhou.aliyuncs.com/";
    private ImageView imageView;
    private TextView contentView;
    private TextView priceView;

    public OptionAdapter(Context context, List<MaterialListEntity> datas) {
        super(context, R.layout.item_option, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final MaterialListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        imageView = holder.getItem().findViewById(R.id.logo_view);
        contentView = holder.getItem().findViewById(R.id.content_view);
        priceView = holder.getItem().findViewById(R.id.price_view);
        RequestOptions options = new RequestOptions()
                .dontAnimate()
                .placeholder(R.drawable.null_img_list)
                .error(R.drawable.null_img_list)
                .centerCrop();
        String imgUrl = appIconUrl + entity.getImageList().get(0);

        Glide.with(imageView.getContext())
                .load(imgUrl)
                .apply(options)
                .into(imageView);

        String shortName = TextUtils.isEmpty(entity.getShortName()) ? "" : "|" + entity.getShortName();

        contentView.setText(entity.getBrandName() + shortName + "|" + entity.getAreaName() + entity.getStorageName());
        priceView.setText("￥ " + StringUtil.showPrice(entity.getPrice()) + "/" + entity.getUnit());
    }

}
